package com.cn.zpark;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: CookieDemo03
 * @Description:
 * @author: RZS
 * @date: 2022/4/14  11:12
 */
@WebServlet("/cook3")
public class CookieDemo03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 创建cookie对象
        Cookie c1 = new Cookie("WEB", "javaWEB");
        // 设置cookie的有效时间，单位秒
        c1.setMaxAge(60);
        // 添加cookie到响应头中
        response.addCookie(c1);
    }
}
